package com.luxiu.extensionlib.base

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider

abstract class BaseViewModelFactory(
     val application: Application
) : ViewModelProvider.Factory {
    override fun <T : ViewModel> create(modelClass: Class<T>): T {
        if (BaseViewModel::class.java.isAssignableFrom(modelClass)) {
            return getViewModel(application)
        }
        throw IllegalArgumentException("Unknown ViewModel class")
    }

    abstract fun <T : BaseViewModel> getViewModel(application:Application): T
}

abstract class BaseViewModel(
    application: Application
) : AndroidViewModel(application)
